home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Experimental BBS Explossion 3
/
Experimental BBS Explossion III.iso
/
c
/
cp1.zip
/
MYLINE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-14
|
3KB
|
90 lines
===========================================================================
BBS: The Abacus * HST/DS * Potterville MI
Date: 06-13-93 (12:23) Number: 141
From: DAVID NUGENT Refer#: NONE
To: ALL Recvd: NO
Subj: [10 of 12] myLine.cpp Conf: (37) C++ Langua
---------------------------------------------------------------------------
// myLine.cpp
//
// 13 Jun 93 Init array[0] = NUL in case it is reference before use
// memcpy() adjusted to also copy terminating NUL from is.get()
// when extending buffer
//
# include <iostream.h>
# include "myLine.h"
# if defined(_MSC_VER)
# include <memory.h>
# else
# include <stdlib.h>
# endif
// Class implementation
myLine::myLine (short buflen)
: len(buflen), mybuf(new char[len]), xalloc(1)
{
mybuf[0] = 0;
}
myLine::myLine (char * usebuf, short buflen)
: len(buflen), mybuf(usebuf), xalloc(0)
{
mybuf[0] = 0;
}
myLine::~myLine (void)
{
if (xalloc)
delete [] mybuf;
}
istream &
operator>> (istream & is, myLine & l)
{
# if AUTO_GROW
if (!l.xalloc) // It's not my buf, so it can't be grown
{
# endif
is.get (l.mybuf, l.len);
if (is.peek() == '\n')
is.get(); // Remove newline from stream
# if AUTO_GROW
}
else
{
int idx = 0;
l.mybuf[0] = 0; // Terminate in case is.good() isn't
for (int eol = 0; !eol && is.good(); )
{
int toget = l.len - idx;
is.get (l.mybuf + idx, toget);
int chrs = is.gcount();
if (is.peek() == '\n')
{
++eol; // Must be eol or eof
is.get(); // Clear newline
}
else if (chrs)
{ // Extend buffer
idx += chrs; // Add to index
l.len = short(l.len + ALLOC_LEN);
char * tmp = new char[l.len];
memcpy (tmp, l.mybuf, idx + 1);
delete [] l.mybuf;
l.mybuf = tmp;
}
}
}
# endif
return is;
}
--- MaltEd 1.0.b5
* Origin: Unique Computing Pty Ltd (3:632/348)
SEEN-BY: 1/211 11/2 4 13/13 101/1 109/25 114/5 123/19 124/1 153/752 154/40
SEEN-BY: 154/77 157/110 159/100 125 140 180 270 430 575 950 203/23 209/209
SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2430/1 2440/5 3603/20